import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

def entropy_func(data):
    '''
    熵 公式
    :param data: list or tuple, 待计算熵数据
    :return: 熵值
    '''
    entropy = 0
    for ix in set(data):
        p_value = data.count(ix) / len(data)
        entropy -= p_value * np.log2(p_value)
    
    return entropy

n_count = 20
b10_list = []
a2_list = []
for ix in range(n_count):
    b10_list.append(np.random.randint(10))
    a2_list.append(np.random.randint(2))

print(b10_list)
print(a2_list)
print(entropy_func(b10_list))
print(entropy_func(a2_list))